/* 
** Copyright (C) 2006  sejishikong <sejishikong@263.net>
** Authors:    sejishikong <sejishikong@263.net>
**             Wei Lian <lianwei3@gmail.com> 
** Maintainer: Wei Lian
**    This program is free software; you can redistribute it and/or modify
**    it under the terms of the GNU General Public License Version 2 as
**    published by the Free Software Foundation;
**
**    This program is distributed in the hope that it will be useful,
**    but WITHOUT ANY WARRANTY; without even the implied warranty of
**    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
**    GNU General Public License for more details.
**
**    You should have received a copy of the GNU General Public License
**    along with this program; if not, write to the Free Software
**    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**
*/

#include "header.h"
#include "tabwidget.h"
#include "record.h"
#include "pageplay.h"
#include "tabbar.h"

TabWidget::TabWidget (QWidget * parent, const char *name):
QTabWidget (parent, name)
{
   ///use custom  tabbar
   tabbar = new TabBar (this);
   setTabBar (tabbar);
   ///topleft corner widget
   QToolButton *but = new QToolButton (this);
   but->setTextLabel ("p");
   but->setAutoRaise (true);
   but->setUsesTextLabel (true);
   setCornerWidget (but, Qt::TopLeft);
   connect (but, SIGNAL (clicked ()), this, SLOT (playTab ()));
   ///topright corner widget
   but = new QToolButton (this);
   but->setTextLabel ("r");
   but->setAutoRaise (true);
   but->setUsesTextLabel (true);
   setCornerWidget (but, Qt::TopRight);
   connect (but, SIGNAL (clicked ()), this, SLOT (recordTab ()));
   ///tab play
   PagePlay *pageplay = new PagePlay (this);
   addTab (pageplay, tr ("play"));
   setTabToolTip (pageplay, "play");
   showPage (pageplay);

   setMaximumHeight (sizeHint ().height ());
}


void
TabWidget::playTab ()
{
   PagePlay *pageplay = new PagePlay (this);
   addTab (pageplay, tr ("play"));
   setTabToolTip (pageplay, "play");
   showPage (pageplay);
}


void
TabWidget::recordTab ()
{
   Record *record = new Record (this);
   addTab (record, tr ("record"));
   setTabToolTip (record, "record");
   showPage (record);
}


void
TabWidget::mouseDoubleClickEvent (QMouseEvent * e)
{
   QPoint p (e->pos ());
   QRect pr (rect ());
   pr.setHeight (tabbar->height ());
   //mouse stay outside of tabbar area
   if (!pr.contains (p))
      return;

   if (e->button () == QMouseEvent::LeftButton)
      playTab ();
   else if (e->button () == QMouseEvent::RightButton)
      recordTab ();
}
